<template>
  <div class="form-widget form-custom-son-table">
    <x-proxy-form-item
      :isInTable="widget.isInTable"
      :showRequired="showRequired"
      :label="widget.label"
      :validatorRules="validatorRules"
      :validateKey="validateKey"
      :validateInfo="validateInfo"
    >
      <div class="parameterPageMobileContract">
        <div class="list">
          <ul class="item">
            <li class="item-single">
              <div style="display: flex;justify-content: center;align-items: stretch;height: 100%;">
                <div style="width: 25%;background-color: #f5a623;">
                  <span class="item-single-title">标题</span>
                </div>
                <div style="width: 75%">
              <span
                class="item-single-value">{{'PETG-合同申请-' + formData[getUuidByName('申请人')][0].username + '-' + formData[getUuidByName('申请日期')]}}</span>
                </div>
              </div>
            </li>

<!--            <li class="item-single">
              <div style="display: flex;justify-content: center;align-items: stretch;height: 100%;">
                <div style="width: 25%;background-color: #f5a623;">
                  <span class="item-single-title">业务员</span></div>
                <div style="width: 75%">
                  <span class="item-single-value">{{formData[getUuidByName('业务员')][0].username}}</span></div>
              </div>
            </li>-->

            <li class="item-single">
              <div style="display: flex;justify-content: center;align-items: stretch;height: 100%;">
                <div style="width: 25%;background-color: #f5a623;">
                  <span class="item-single-title">业务实体</span></div>
                <div style="width: 75%">
                  <span class="item-single-value">{{formData[getUuidByName('业务实体')][0].name}}</span></div>
              </div>
            </li>
            <li class="item-single">
              <div style="display: flex;justify-content: center;align-items: stretch;height: 100%;">
                <div style="width: 25%;background-color: #f5a623;">
                  <span class="item-single-title">客户名称</span></div>
                <div style="width: 75%">
                  <span class="item-single-value">{{formData[getUuidByName('客户名称')][0].name}}</span></div>
              </div>
            </li>

            <li class="item-single">
              <div style="display: flex;justify-content: center;align-items: stretch;height: 100%;">
                <div style="width: 25%;background-color: #f5a623;">
                  <span class="item-single-title">业务员</span></div>
                <div style="width: 75%">
                  <span class="item-single-value">{{formData[getUuidByName('业务员')][0].username}}</span></div>
              </div>
            </li>

            <li class="item-single">
              <div style="display: flex;justify-content: center;align-items: stretch;height: 100%;">
                <div style="width: 25%;background-color: #f5a623;">
                  <span class="item-single-title">合同有效期起</span></div>
                <div style="width: 75%">
                  <span class="item-single-value">{{formData[getUuidByName('合同有效期起')]}}</span></div>
              </div>
            </li>
            <li class="item-single">
              <div style="display: flex;justify-content: center;align-items: stretch;height: 100%;">
                <div style="width: 25%;background-color: #e4f3fc;">
                  <span class="item-single-title">合同有效期止</span></div>
                <div style="width: 75%">
                  <span class="item-single-value">{{formData[getUuidByName('合同有效期止')]}}</span></div>
              </div>
            </li>
            <li class="item-single">
              <div style="display: flex;justify-content: center;align-items: stretch;height: 100%;">
                <div style="width: 25%;background-color: #f5a623;">
                  <span class="item-single-title">销售类型</span></div>
                <div style="width: 75%">
                  <span class="item-single-value">{{formData[getUuidByName('销售类型')][0].name}}</span></div>
              </div>
            </li>
            <li class="item-single">
              <div style="display: flex;justify-content: center;align-items: stretch;height: 100%;">
                <div style="width: 25%;background-color: #f5a623;">
                  <span class="item-single-title">币种</span></div>
                <div style="width: 75%">
                  <span class="item-single-value">{{formData[getUuidByName('币种')][0].name}}</span></div>
              </div>
            </li>
            <li class="item-single">
              <div style="display: flex;justify-content: center;align-items: stretch;height: 100%;">
                <div style="width: 25%;background-color: #e4f3fc;">
                  <span class="item-single-title">税率</span></div>
                <div style="width: 75%">
                  <span class="item-single-value">{{formData[getUuidByName('税率')][0].name}}
                  </span></div>
              </div>
            </li>
            <li class="item-single">
              <div style="display: flex;justify-content: center;align-items: stretch;height: 100%;">
                <div style="width: 25%;background-color: #f5a623;">
                  <span class="item-single-title">L/C</span></div>
                <div style="width: 75%">
                  <span class="item-single-value">
                   {{ formData[getUuidByName('L/C')]?dictMap['YORN'][formData[getUuidByName('L/C')][0]] : ''}}
                  </span></div>
              </div>
            </li>
            <li class="item-single">
              <div style="display: flex;justify-content: center;align-items: stretch;height: 100%;">
                <div style="width: 25%;background-color: #f5a623;">
                  <span class="item-single-title">付款条件</span></div>
                <div style="width: 75%">
                  <span class="item-single-value">{{formData[getUuidByName('付款条件')][0].name}}</span></div>
              </div>
            </li>
            <li class="item-single">
              <div style="display: flex;justify-content: center;align-items: stretch;height: 100%;">
                <div style="width: 25%;background-color: #f5a623;">
                  <span class="item-single-title">结算方式</span></div>
                <div style="width: 75%">
                  <span class="item-single-value">{{formData[getUuidByName('结算方式')][0].name}}</span></div>
              </div>
            </li>
            <li class="item-single">
              <div style="display: flex;justify-content: center;align-items: stretch;height: 100%;">
                <div style="width: 25%;background-color: #f5a623;">
                  <span class="item-single-title">数量合计</span></div>
                <div style="width: 75%">
                  <span class="item-single-value">{{formData[getUuidByName('数量合计')]}}</span></div>
              </div>
            </li>
            <li class="item-single">
              <div style="display: flex;justify-content: center;align-items: stretch;height: 100%;">
                <div style="width: 25%;background-color: #f5a623;">
                  <span class="item-single-title">不含税合计</span></div>
                <div style="width: 75%">
                  <span class="item-single-value">{{formData[getUuidByName('不含税合计')]}}</span></div>
              </div>
            </li>

<!--            <li class="item-single">
              <div style="display: flex;justify-content: center;align-items: stretch;height: 100%;">
                <div style="width: 25%;background-color: #f5a623;">
                  <span class="item-single-title">备注</span></div>
                <div style="width: 75%">
                  <span class="item-single-value">{{formData[getUuidByName('备注')]}}</span></div>
              </div>
            </li>-->

          </ul>
          <!--    合同申请明细表      -->
          <div class="son-table">
            <ul class="son-list-single">
              <li class="th">牌号</li>
              <li class="th">等级</li>
              <li class="th">出仓单价</li>
              <li class="th">始发地</li>
              <li class="th" v-if="getIsShow()==0">目的地</li>
              <li class="th" v-if="getIsShow()==1">自提港</li>
              <li class="th">成交单价</li>
              <li class="th">参考运费</li>
              <li class="th">预估运费</li>
            </ul>

            <div class="son-table-body">
              <template v-for="(item,index) in childrenData">
                <ul class="tr">
                  <li class="thv">{{ item[getChildUuidByName('牌号')][0].name }}</li>
                  <li class="thv">{{ item[getChildUuidByName('等级')] }}</li>
                  <li class="thv">{{ item[getChildUuidByName('出仓单价')] }}</li>
                  <li class="thv">{{ item[getChildUuidByName('始发地')]?
                    dictMap['ORIGIN'][item[getChildUuidByName('始发地')][0]] : ''  }}</li>
                  <li class="thv" v-if="getIsShow()==0">{{ item[getChildUuidByName('目的地')][0].name }}</li>
                  <li class="thv" v-if="getIsShow()==1">{{ item[getChildUuidByName('自提港')]?
                    dictMap['PORT'][item[getChildUuidByName('自提港')][0]]: '' }}</li>
                  <li class="thv">{{ item[getChildUuidByName('成交单价')] }}</li>
                  <li class="thv">{{ item[getChildUuidByName('参考运费单价')] }}</li>
                  <li class="thv">{{ item[getChildUuidByName('预估运费单价')] }}</li>
                </ul>
              </template>
            </div>
          </div>
        <!--  下一个列表页面     -->
          <div class="list">
            <ul class="item">
              <li class="item-single">
                <div style="display: flex;justify-content: center;align-items: stretch;height: 100%;">
                  <div style="width: 25%;background-color: #f5a623;">
                    <span class="item-single-title">合同编号</span></div>
                    <div style="width: 75%">
                    <span class="item-single-value">{{formData[getUuidByName('合同编号')]}}</span></div>
                </div>
              </li>
              <li class="item-single">
                <div style="display: flex;justify-content: center;align-items: stretch;height: 100%;">
                  <div style="width: 25%;background-color: #f5a623;">
                    <span class="item-single-title">包装方式</span></div>
                  <div style="width: 75%">
                    <span class="item-single-value">{{formData[getUuidByName('包装方式')][0].name}}</span></div>
                </div>
              </li>
              <li class="item-single">
                <div style="display: flex;justify-content: center;align-items: stretch;height: 100%;">
                  <div style="width: 25%;background-color: #f5a623;">
                    <span class="item-single-title">发运方式</span></div>
                  <div style="width: 75%">
                    <span class="item-single-value">{{formData[getUuidByName('发运方式')][0].name}}</span></div>
                </div>
              </li>
              <li class="item-single">
                <div style="display: flex;justify-content: center;align-items: stretch;height: 100%;">
                  <div style="width: 25%;background-color: #f5a623;">
                    <span class="item-single-title">销售部门</span></div>
                  <div style="width: 75%">
                    <span class="item-single-value">{{formData[getUuidByName('销售部门')][0].name}}</span></div>
                </div>
              </li>
              <li class="item-single">
                <div style="display: flex;justify-content: center;align-items: stretch;height: 100%;">
                  <div style="width: 25%;background-color: #f5a623;">
                    <span class="item-single-title">申请人</span></div>
                  <div style="width: 75%">
                    <span class="item-single-value">{{formData[getUuidByName('申请人')][0].username}}</span></div>
                </div>
              </li>
              <li class="item-single">
                <div style="display: flex;justify-content: center;align-items: stretch;height: 100%;">
                  <div style="width: 25%;background-color: #f5a623;">
                    <span class="item-single-title">申请部门</span></div>
                  <div style="width: 75%">
                    <span class="item-single-value">{{formData[getUuidByName('申请部门')][0].name}}</span></div>
                </div>
              </li>
              <li class="item-single">
                <div style="display: flex;justify-content: center;align-items: stretch;height: 100%;">
                  <div style="width: 25%;background-color: #f5a623;">
                    <span class="item-single-title">申请日期</span></div>
                  <div style="width: 75%">
                    <span class="item-single-value">{{formData[getUuidByName('申请日期')]}}</span></div>
                </div>
              </li>

              <li class="item-single">
                <div style="display: flex;justify-content: center;align-items: stretch;height: 100%;">
                  <div style="width: 25%;background-color: #f5a623;">
                    <span class="item-single-title">佣金代理商</span></div>
                  <div style="width: 75%">
                    <span class="item-single-value">{{formData[getUuidByName('佣金代理商')][0].name}}</span></div>
                </div>
              </li>

              <li class="item-single">
                <div style="display: flex;justify-content: center;align-items: stretch;height: 100%;">
                  <div style="width: 25%;background-color: #f5a623;">
                    <span class="item-single-title">行业类型</span></div>
                  <div style="width: 75%">
                    <span class="item-single-value">{{formData[getUuidByName('行业类型')][0].name}}</span></div>
                </div>
              </li>

              <li class="item-single">
                <div style="display: flex;justify-content: center;align-items: stretch;height: 100%;">
                  <div style="width: 25%;background-color: #f5a623;">
                    <span class="item-single-title">区域</span></div>
                  <div style="width: 75%">
                    <span class="item-single-value">{{formData[getUuidByName('区域')]}}</span></div>
                </div>
              </li>

              <li class="item-single">
                <div style="display: flex;justify-content: center;align-items: stretch;height: 100%;">
                  <div style="width: 25%;background-color: #f5a623;">
                    <span class="item-single-title">目的港</span></div>
                  <div style="width: 75%">
                    <span class="item-single-value">{{formData[getUuidByName('目的港')]}}</span></div>
                </div>
              </li>

              <li class="item-single">
                <div style="display: flex;justify-content: center;align-items: stretch;height: 100%;">
                  <div style="width: 25%;background-color: #f5a623;">
                    <span class="item-single-title">收单地址</span></div>
                  <div style="width: 75%">
                    <span class="item-single-value">{{formData[getUuidByName('收单地址')]}}</span></div>
                </div>
              </li>

              <li class="item-single">
                <div style="display: flex;justify-content: center;align-items: stretch;height: 100%;">
                  <div style="width: 25%;background-color: #f5a623;">
                    <span class="item-single-title">收货地址</span></div>
                  <div style="width: 75%">
                    <span class="item-single-value">{{formData[getUuidByName('收货地址')][0].name}}</span></div>
                </div>
              </li>

              <li class="item-single">
                <div style="display: flex;justify-content: center;align-items: stretch;height: 100%;">
                  <div style="width: 25%;background-color: #f5a623;">
                    <span class="item-single-title">备注</span></div>
                  <div style="width: 75%">
                    <span class="item-single-value">{{formData[getUuidByName('备注')]}}</span></div>
                </div>
              </li>

              <li class="item-single">
                <div style="display: flex;justify-content: center;align-items: stretch;height: 100%;">
                  <div style="width: 25%;background-color: #f5a623;">
                    <span class="item-single-title">附件</span></div>
                  <div style="width: 75%">
                    <span class="item-single-value" v-for="item in formData[getUuidByName('附件')]" >
                 <div class="file-single">
                  <img :src="require('../../../../../../assets/'+  matchType(item.fileName)  +'.png')"
                        style="width: 16px;
                         height: 16px;
                      ">{{item.fileName}}</div>
                 <div style="

                   padding: 5px 5px 5px 5px;
                   width: 40px;
                   border-radius: 5px;
                   box-shadow: 0 1px 8px rgba(0,0,0,0.3);
                   margin-top: 5px;
                   vertical-align: middle;
                   text-align: center;
                ">
                 <a style="
                           color: rgb(19, 19, 19);
                           border: 1px solid rgb(242, 242, 242);
                           margin-top: 10px;
                           border-radius: 6px;
                           background: rgb(255, 255, 255);
                " @click="downloadFileContract(item)">下载</a></div>
                 </span>
                  </div>
                </div>
              </li>

            </ul>
          </div>


        </div>
      </div>
    </x-proxy-form-item>
  </div>
</template>

<script>
import FormWidgetConfigMixin from '@/mixin/form-widget.mixin'
export default {
  name: 'ContractapplicationRead',
  mixins: [FormWidgetConfigMixin],
  components: {},
  data: function () {
    return {
      dictMap:{
        'YORN':{
          'N':'否',
          'Y':'是'
        },
        'ORIGIN':{
          'ZH':'珠海',
          'CZ':'常州'
        },
        'PORT':{
          'ZH':'珠海',
          'CZ':'常州',
          'SH':'上海',
          'SZ':'深圳',
          'NS':'南沙',
          'HW':'洪湾'
        }
      },
      mainData:{},
      childrenData:[]
    }
  },
  computed: {},
  created() {
    this.getData()
    this.getIsShow()
  },
  methods: {
    getIsShow(){
      if (this.formData[this.getUuidByName('销售类型')][0].name == 'PETG-外销'){
        return 1;
      }else {
        return 0;
      }
    },
    getDownloadUrlContract(url){
      const {$store, $base64} = this;
      const tenantId = $store?.state?.tenantModule?.currentOrg?.id;
      const token = $store?.state?.authModule?.token;
      const tokenBase64 = $base64.encode(
        JSON.stringify({
          xdaptenantid: tenantId,
          xdaptoken: token
        })
      );

      // return url.replace("http://apaas-dev.crcchem.com/chem-crcchem-oms","").replace("http://apaas.crcchem.com/chem-crcchem-oms","") + `&token=${tokenBase64}`
      return url + `&token=${tokenBase64}`
    },
    downloadFileContract(item){
      let ur = this.getDownloadUrlContract(item.url) //url 参数 包含 file token
      let uuid = '&uuid='+this.getUuidByName('附件')
      let download = '&download=download'
      let formId = '&fromId='+this.globalData.formId
      let url = ur+download+formId+uuid
      const a = document.createElement('a'); // 创建一个HTML 元素
      a.setAttribute('download', ''); //download属性
      a.setAttribute('href', url); // href链接
      a.click(); // 自执行点击事件
    },
    getData(){
      this.mainData = {}
      this.childrenData = this.formData[this.getTableUuidByName('产品明细')]

    },
    // 根据自开发组件label获取对应表单子表tableUuid
    getTableUuidByName(name) {
      let tempUuid = ''
      this.formEngine.formDataControl.componentMap.forEach((value, key) => {
        if (value.label === name && value.componentType === 'FORM_WIDGET_SON_TABLE') {
          tempUuid = value.uuid
        }
      })
      return tempUuid },
    // 根据自开发组件label获取对应表单 子表uuid
    getChildUuidByName(name) {
      let tempUuid = ''
      this.formEngine.formDataControl.componentMap.forEach((value, key) => {
        if (value.label === name && value.tableUuid) {
          tempUuid = value.uuid
        }
      })
      return tempUuid },

    // 根据自开发组件label获取对应表单 主表uuid
    getUuidByName(name) {
      let tempUuid = ''
      this.formEngine.formDataControl.componentMap.forEach((value, key) => {
        if (value.label === name && !value.tableUuid) {
          tempUuid = value.uuid
        }
      })
      return tempUuid
    },

    matchType(fileName){
      console.log("fileName = ",fileName)
      // 后缀获取
      var suffix = '';
      // 获取类型结果
      var result = '';
      try {
        var flieArr = fileName.split('.');
        suffix = flieArr[flieArr.length - 1];
      } catch (err) {
        suffix = '';
      }
      // fileName无后缀返回 false
      if (!suffix) {
        result = false;
        return result;
      }
      // 图片格式
      var imglist = ['png', 'jpg', 'jpeg', 'bmp', 'gif'];
      // 进行图片匹配
      result = imglist.some(function (item) {
        return item == suffix;
      });
      if (result) {
        result = 'image';
        return result;
      };
      // 匹配txt
      var txtlist = ['txt'];
      result = txtlist.some(function (item) {
        return item == suffix;
      });
      if (result) {
        result = 'txt';
        return result;
      };
      // 匹配 excel
      var excelist = ['xls', 'xlsx'];
      result = excelist.some(function (item) {
        return item == suffix;
      });
      if (result) {
        result = 'excel';
        return result;
      };
      // 匹配 word
      var wordlist = ['doc', 'docx'];
      result = wordlist.some(function (item) {
        return item == suffix;
      });
      if (result) {
        result = 'word';
        return result;
      };
      // 匹配 pdf
      var pdflist = ['pdf'];
      result = pdflist.some(function (item) {
        return item == suffix;
      });
      if (result) {
        result = 'pdf';
        return result;
      };
      // 匹配 ppt
      var pptlist = ['ppt'];
      result = pptlist.some(function (item) {
        return item == suffix;
      });
      if (result) {
        result = 'ppt';
        return result;
      };
      // 匹配 视频
      var videolist = ['mp4', 'm2v', 'mkv'];
      result = videolist.some(function (item) {
        return item == suffix;
      });
      if (result) {
        result = 'video';
        return result;
      };
      // 匹配 音频
      var radiolist = ['mp3', 'wav', 'wmv'];
      result = radiolist.some(function (item) {
        return item == suffix;
      });
      if (result) {
        result = 'radio';
        return result;
      };
      // 匹配 压缩包
      var packagelist = ['zip', 'rar', 'tar'];
      result = packagelist.some(function (item) {
        return item == suffix;
      });
      if (result) {
        result = 'zip';
        return result;
      };
      // 匹配 CSV
      var CSVlist = ['csv'];
      result = CSVlist.some(function (item) {
        return item == suffix;
      });
      if (result) {
        result = 'csv';
        return result;
      };
      // 其他 文件类型
      result = 'other';
      return result;

    }




  }
}
</script>

<style lang="scss">

.form-custom-son-table {


  .parameterPageMobileContract {
    width: 100vw;
    height: auto;

    .list {
      height: 100%;
      overflow: visible;
      padding: 0;
    }
    .item-single{
      margin: 0 !important;
    }

    .item-single-value {
      width: 98%;
      word-break: break-all;
      white-space: normal;
      margin-left: 5px;
    }

    .item-single-title {
      width: 100%;
      font-weight: 900;
      background-color: #f5a623;
      color: #fff !important;
    }

    .item {
      margin: 0;
      padding: 0;

      li {
        list-style: none;
        border: 1px solid #dcdfe6;

        span {
          padding: 8px 0 8px 0;
          color: #555;
        }

        span:first-child {
          display: inline-block;


          border-right: 1px solid #dcdfe6;
        }
      }

      li + li {
        border-top: none;
      }

      li:last-child {
        border-radius: 0 0 4px 4px
      }
    }

    .son-table {
      height: auto;
      border-top: #dcdfe6 1px solid;
      border-left: #dcdfe6 1px solid;
      border-bottom: #dcdfe6 1px solid;
      padding: 0;
      margin: 0 auto;
      margin-top: 10px;
      font-size: 12px;
      overflow: hidden;

      .th {
        color: #fff;
        border-right: 1px solid #d7d7d7;
      }
      .thv{
        color: #555555;
        border-right: 1px solid #d7d7d7;
      }

      .son-list-single {
        width: 100%;
        display: grid;
        grid-template-columns: 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr 18px;
        text-align: center;
        list-style: none;
        line-height: 2.6rem;
        background-color: #f5a623;
      }

      .son-table-body {
        overflow: hidden;

        .tr {
          width: 100%;
          display: grid;
          grid-template-columns: 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr 18px;
          text-align: center;
          list-style: none;
          line-height: 2.6rem;
          border-bottom: 1px solid #dcdfe6;
        }
      }
    }


  }
}
</style>
